package com.skstudio.report;

import java.util.ArrayList;

public class ReportMem extends ReportBase {
	public static class DataMem {
		public long mTotal, mFree, mUsed;
		public float mFreePctage = 0.f, mUsedPctage = 0.f;
		
		public void Read(byte[] buffer, int offset) {
			mTotal = getCxxUnsignedLong(buffer, offset + 0);
			mUsed = getCxxUnsignedLong(buffer, offset + 4);
			mFree = getCxxUnsignedLong(buffer, offset + 8);
			
			mFreePctage = (float) (mFree * 100.0) / (float)(mTotal);
			mUsedPctage = (float) (mUsed * 100.0) / (float)(mTotal);
		}
		
		public float getFree() {
			return mFreePctage;
		}
		
		public float getUsed() {
			return mUsedPctage;
		}
	}

	public ArrayList < DataMem > mDataList = new ArrayList < DataMem > ();

	@Override
	public void parse(byte[] buffer, int offset)
	{
		DataMem dc = new DataMem();
		dc.Read(buffer, offset);
		if (mDataList.size() == getMaxQueueSize()) {
			mDataList.remove(0);
		}
		mDataList.add(dc);	
		//Log.v("DataMem", "Total " + dc.mTotal + ", free " + dc.mFree + ", used " + dc.mUsed);
	}
	
	@Override
	public void reset() {
		mDataList.clear();
	}
}
